package com.yilin.platform.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yilin.platform.base_core.tools.QueryUtil;
import com.yilin.platform.entity.system.TruckEnergyType;
import com.yilin.platform.entity.system.TruckPlate;
import com.yilin.platform.entity.system.TruckType;
import com.yilin.platform.mapper.system.TruckEnergyTypeMapper;
import com.yilin.platform.mapper.system.TruckPlateMapper;
import com.yilin.platform.mapper.system.TruckTypeMapper;
import com.yilin.platform.service.system.IParamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Service
@Transactional
public class ParamService   implements IParamService {

    @Resource
    TruckPlateMapper truckPlateMapper;
    @Resource
    TruckEnergyTypeMapper truckEnergyTypeMapper;
    @Resource
    TruckTypeMapper truckTypeMapper;

    //#################################################【前台列表区】############################################################



    @Override
    public List<TruckEnergyType> getTruckEnergyTypeList(TruckEnergyType truckEnergyType) {
        if (truckEnergyType.getSort() == null) truckEnergyType.setSort("id-ASC");
        return truckEnergyTypeMapper.selectList(QueryUtil.andQueryWrapper(new QueryWrapper<>(), truckEnergyType));
    }

    @Override
    public List<TruckPlate> getTruckPlateList(TruckPlate truckPlate) {
        if (truckPlate.getSort() == null) truckPlate.setSort("id-ASC");
        return truckPlateMapper.selectList(QueryUtil.andQueryWrapper(new QueryWrapper<>(), truckPlate));
    }

    @Override
    public List<TruckType> getTreeTruckTypeList(TruckType truckType) {
        if (truckType.getSort() == null) truckType.setSort("id-ASC");
        return truckTypeMapper.selectList(QueryUtil.andQueryWrapper(new QueryWrapper<>(), truckType));
    }

    //#################################################【编辑区】############################################################


    @Override
    public void editTruckEnergyType(TruckEnergyType truckEnergyType) {
        if (truckEnergyType.getId() == null) {
            truckEnergyType.setCreateTime(new Date());
            truckEnergyTypeMapper.insert(truckEnergyType);
        } else {
            truckEnergyType.setUpdateTime(new Date());
            truckEnergyTypeMapper.updateById(truckEnergyType);
        }
    }

    @Override
    public void editTruckPlate(TruckPlate truckPlate) {
        if (truckPlate.getId() == null) {
            truckPlate.setCreateTime(new Date());
            truckPlateMapper.insert(truckPlate);
        } else {
            truckPlate.setUpdateTime(new Date());
            truckPlateMapper.updateById(truckPlate);
        }
    }

    @Override
    public void editTruckType(TruckType truckType) {
        if (truckType.getId() == null) {
            truckType.setCreateTime(new Date());
            truckTypeMapper.insert(truckType);
        } else {
            truckType.setUpdateTime(new Date());
            truckTypeMapper.updateById(truckType);
        }
    }


    //#################################################【删除区】############################################################

    @Override
    public void deleteTruckEnergyType(TruckEnergyType truckEnergyType) {
        truckEnergyTypeMapper.deleteById(truckEnergyType);
    }

    @Override
    public void deleteTruckPlate(TruckPlate truckPlate) {
        truckPlateMapper.deleteById(truckPlate);
    }

    @Override
    public void deleteTruckType(TruckType truckType) {
        truckTypeMapper.deleteById(truckType);
    }



    //#################################################【列表检索】############################################################



    @Override
    public List<TruckType> getTruckTypeList(TruckType.IsTrailer isTrailer) {
        return truckTypeMapper.selectList(new QueryWrapper<TruckType>().eq("is_trailer", isTrailer));
    }

    @Override
    public List<TruckEnergyType> getTruckEnergyTypeList() {
        return truckEnergyTypeMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public List<TruckPlate> getTruckPlateList() {
        return truckPlateMapper.selectList(new QueryWrapper<>());
    }


    //通过车辆名称检索车辆类型
    @Override
    public List<TruckType> queryTruckTypeByName(String name) {
        return truckTypeMapper.selectList(new QueryWrapper<TruckType>().eq("name", name));
    }



    //#################################################【单条检索】############################################################

    @Override
    public TruckEnergyType getTruckEnergyTypeByName(String name) {
        return truckEnergyTypeMapper.selectOne(new QueryWrapper<TruckEnergyType>().eq("name", name));
    }

    @Override
    public TruckType getTruckTypeById(String TruckTypeId) {
        return truckTypeMapper.selectOne(new QueryWrapper<TruckType>().eq("id", TruckTypeId));
    }

    @Override
    public TruckPlate getTruckPlateById(String id) {
        return truckPlateMapper.selectOne(new QueryWrapper<TruckPlate>().eq("id", id));
    }


    //通过能源名称检索能源类型
    @Override
    public TruckEnergyType queryTruckEnergyTypeByName(String name) {
        return truckEnergyTypeMapper.selectOne(new QueryWrapper<TruckEnergyType>().eq("name", name));
    }


    //通过车牌名称获取车牌类型
    @Override
    public TruckPlate queryTruckPlateByName(String name) {
        return truckPlateMapper.selectOne(new QueryWrapper<TruckPlate>().eq("name", name));
    }



    @Override
    public TruckEnergyType getTruckEnergyById(String truckEnergyTypeId) {
        return truckEnergyTypeMapper.selectById(truckEnergyTypeId);
    }

    /**
     * 为银行联行号添加银行简称 该方法请谨慎调用!!!
     */


}
